Contents
[ ]:
# Title
[5]:
import pandas as pd
[6]:
col_names ={'year':'UTC',
'mo':'UTC',
'day':'UTC',
'hr':'UTC',
'yday':'UTC',
'BPR':'mbar',
'ATMP':'degC',
'STMP':'degC',
'WNDE':'m/s',
'WNDN':'m/s',
'WSPD':'m/s',
'WDIR':'deg',
'RH':'%',
'SRAD':'W/m2',
'LRAD':'W/m2',
'PRC':'mm',
'PRATE':'mm/hr',
'SAL':'l',
'COND':'S/m'}
[7]:
#def get_whots_system():
# WHOTS SYSTEM 1QC and 2QC DATA
whots17_sys1_qc=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys1QC.txt']
whots17_sys2_qc=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys2QC.txt']
# WHOTS SYSTEM 1 and 2 NOT QC DATA
whots17_sys1=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys1.txt']
whots17_sys2=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys2.txt']
[8]:
whots17_sys1=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys1.txt']
whots17_sys2=['http://uop.whoi.edu/currentprojects/WHOTS/data/WHOTS-XVII_MET_sys2.txt']
for system,url in enumerate([whots17_sys1,whots17_sys2]):
df = pd.read_csv(url[0],
skiprows = 5,
delim_whitespace=True,
names = col_names.keys(),
index_col= False
)
df.index=(df['year'].map(str) +
'-' + df['mo'].map(str) +
'-' + df['day'].map(str) +
' ' + df['hr'].map(str)
)
if system == 0:
df1 = df # save system 1
else:
df2 = df # save system 2
[15]:
from ipywidgets import Button, HBox
import plotly.offline as py
import plotly.graph_objs as go
from plotly.subplots import make_subplots
# To initialize plotly for notebook usage
py.init_notebook_mode()
plot_all_whots=(['RH', 'ATMP', 'BPR', 'SRAD', 'LRAD'], # First Plot
['STMP', 'SAL', 'COND', 'PRC', 'PRATE'], # Second Plot
['WSPD', 'WDIR', 'WNDN', 'WNDE','BPR']) # Third Plot
# Create 3 figures with 5 subplots each
for counter,variable in enumerate(plot_all_whots):
# Create subplots
fig = make_subplots(
rows=5, cols=1,
shared_xaxes=True,
vertical_spacing=0.05,
specs=[[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}]],
subplot_titles=plot_all_whots[counter][:],
)
# Plot system 1
for counter1, variable1 in enumerate(plot_all_whots[counter][:]):
# Plot variables
fig.add_trace(
go.Scatter(
x=df1.index,
y=df1[variable1],
mode="lines",
name= variable1,
line=dict(color='blue', width=1.5)
),
row=counter1+1, col=1
)
# Plot system 2
for counter2, variable2 in enumerate(plot_all_whots[counter][:]):
# Plot variables
fig.add_trace(
go.Scatter(
x=df2.index,
y=df2[variable2],
mode="lines",
name= variable2,
line=dict(color='red', width=1)
),
row=counter2+1, col=1
)
# Add buttons
fig.update_xaxes(
rangeselector=dict(
buttons=list([
dict(count=1, label="1d", step="day", stepmode="backward"),
dict(count=15, label="15d", step="day", stepmode="backward"),
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
),
rangeslider= {'visible':False}, row=1, col=1,
)
fig['layout'].update(height=800)
fig.update_layout(xaxis=dict(tickformat="%mm"))
fig.show()
[10]:
plot_all_whots = {
"plot1":{
"RH": "%",
"ATMP": "degC",
"BPR": "mbar",
"SRAD": "W/m2",
"LRAD":"W/m2"
},
"plot2":{
"STMP": "degC",
"SAL": "1",
"COND": "S/m",
"PRC": "mm",
"PRATE":"mm/hr"
},
"plot3":{
"WSPD": "m/s",
"WDIR": "deg",
"WNDN": "m/s",
"WNDE": "m/s",
"ATMP":"m/s"
}
}
[11]:
# Calculating the means
monthly_means = df2.groupby("mo").median()
hourly_means = df2.groupby("hr").median()
daily_means = df2.groupby("day").median()
[16]:
monthly_means['STMP'].plot()
[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fa80219bd00>
[13]:
import ipywidgets as widgets
# Create buttons for Stations and Sensors
stationW = widgets.ToggleButtons(options='Stations', orientation='horizontal')
[ ]: